package org.jpro.common.jpa.specification;

import java.util.Date;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 * <P>功能描述 : </P>
 * <P>Method Name : LeSpecification </P>
 * <P>Author : 王泽浩 </P>
 * <P>E-Mail : 1028625100@qq.com </P>
 * <P>Date : 2017-03-14 15:46:15</P>
 * @param <T> the type parameter
 * @since 1.0
 */
public class GtDSpecification<T> extends AbstractSpecification<T> {

    /**
     * The Property.
     */
    private final String property;

    /**
     * The date.
     */
    private final Date date;

    /**
     * <P>功能描述 : </P>
     * <P>Method Name : GtDSpecification </P>
     * <P>Author : 王泽浩 </P>
     * <P>E-Mail : 1028625100@qq.com </P>
     * <P>Date : 2017-03-14 15:46:15</P>
     * @param property the property
     * @param date the number
     * @since 1.0
     */
    public GtDSpecification(String property, Date date) {
        this.property = property;
        this.date = date;
    }

    /**
     * <P>功能描述 : </P>
     * <P>Method Name : toPredicate </P>
     * <P>Author : 王泽浩 </P>
     * <P>E-Mail : 1028625100@qq.com </P>
     * <P>Date : 2017-03-14 15:46:15</P>
     * @param root the root
     * @param query the query
     * @param cb the cb
     * @return the predicate
     * @since 1.0
     */
    @Override
    public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
        From from = getRoot(property, root);
        String field = getProperty(property);
        return cb.greaterThan(from.get(field), date);
    }

}